﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Config_ExecuteSql : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断
    }

    protected void btnSumbit_Click(object sender, EventArgs e)
    {
        string sqlCode = Settings.GetString("SqlCode");
        string sql = txtSQL.Text.ToLower();
        string code = txtCode.Text.Trim();
        if (code != sqlCode)
        {
            JsHelper.Alert(Page, "验证码不正确，请重新输入！");
            return;
        }

        try
        {
            if (sql.StartsWith("select"))
            {
                BindData(sql);
            }
            else
            {
                Whir.SQLServerDAL.DbHelperSQL.ExecuteSql(sql);

            }
        }
        catch (Exception ex)
        {
            JsHelper.Alert(ex.Message);
        }
    }

    private void BindData(string sql)
    {
        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.Query(sql);
        int rowCount = int.Parse(ds.Tables[0].Rows[0][0].ToString());
        if (rowCount > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            GridView1.Controls.Clear();
            divMessage.Visible = true;
        }
    }
}
